#ifndef _BLOCK_STORAGE_H
#define _BLOCK_STORAGE_H

#include <stdlib.h>
#include <sys/time.h>
#include <stdio.h>
#include <ctype.h>

#include "zookeeper.h"
#include "zookeeper_version.h"
#include "recordio.h"
#include "zookeeper.jute.h"
#include "shard.h"

typedef struct{
    int request_type[OUTSTANDING_LIMIT]; //PENDING_READ or PENDING_WRITE
    long next_deadline[OUTSTANDING_LIMIT];
    void *requests[OUTSTANDING_LIMIT];
    int index ;
    int count;
    int first_nonce;
    pthread_mutex_t lock;
    pthread_cond_t cond;
}pending_queue_t;


typedef struct{
    zhandle_t * servers;
    pending_queue_t * pending_queue;
    int64_t client_id;
    int32_t xid;
    int32_t nonce;
    pthread_mutex_t lock;
}block_storage_t;

block_storage_t * block_storage_init(const char* host, const int64_t client_id);

void write_block(block_storage_t * storage, long blockId, char *buf, int buflen, 
	void_completion_t completion, const void *data);

void read_block(block_storage_t * storage, long blockId, data_completion_t completion, const void *data);

void handle_response(block_storage_t * storage, struct ReplyHeader *hdr, struct iarchive *ia, int sid);

#endif
